﻿using RightControl.Common;
using RightControl.IRepository;
using RightControl.IService;
using RightControl.Model;
using RightControl.Repository;
using System.Collections.Generic;

namespace RightControl.Service {
    public class AttrOptionsService : BaseService<AttrOptions>, IAttrOptionsService {
        public IAttrOptionsRepository repository { get; set; }

          public IEnumerable<BasicFields> GetBasicFields(string categoryCode) {
            return CacheHelper.GetCache<IEnumerable<BasicFields>>(string.Format("Cache_{0}", categoryCode), () => {
                return repository.GetBasicFields(categoryCode);
            }, 3600);
        }

        public List<AttrOptions> GetAttrOptionsList(AttrOptions filter, PageInfo pageInfo) {
            return CacheHelper.GetCache<List<AttrOptions>>(string.Format("Cache_{0}", filter.CategoryCode), () => {
                string _where = " 1=1";
                if (filter.CategoryCode.IsNotEmpty()) {
                    _where += string.Format(" And CategoryCode='{0}'", filter.CategoryCode);
                }
                dynamic result = GetListByFilter(filter, pageInfo, _where);
                return result != null ? result.data as List<AttrOptions> : new List<AttrOptions>();
            }, 3600);
        }

        //public List<ExportFields> GetFieldsForTitle(string categoryCode, int fdType) {
        //    ExportFields filter = new ExportFields() { CategoryCode = categoryCode, FdType = fdType };
        //    string _where = GetBaseCondition(filter);
        //    _where += " and Weight >0 ";
        //    PageInfo pageInfo = new PageInfo(1, 1000, "Weight", "Desc");
        //    dynamic result = GetListByFilter(filter, pageInfo, _where);
        //    return result != null ? result.data as List<ExportFields> : new List<ExportFields>();
        //}

        //private static string GetBaseCondition(ExportFields filter) {
        //    string _where = " where Status=1";
        //    if (filter.CategoryCode.IsNotEmpty()) {
        //        _where += string.Format(" and CategoryCode = '{0}'", filter.CategoryCode);
        //    }
        //    if (filter.FdType > 0) {
        //        _where += string.Format(" and FdType = {0}", filter.FdType);
        //    }
        //    return _where;
        //}

        //public bool IsNotExist(ProductDetail filter) {
        //    string _where = " where 1=1";
        //    if (filter.OriProductUrl.IsNotEmpty()) {
        //        _where += string.Format(" and OriProductUrl = '{0}'", filter.OriProductUrl);
        //    }

        //    if (filter.UserId > 0) {
        //        _where += string.Format(" and UserId = {0}", filter.UserId);
        //    }
        //    return GetTotal(new SearchFilter() { pageIndex = 1, pageSize = 100, where = _where }) == 0;
        //}


        public new dynamic GetListByFilter(AttrOptions filter, PageInfo pageInfo) {
            throw new System.NotImplementedException();
        }
    }
}